package com.steve.summary.seata.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.steve.summary.seata.entity.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author: STEVE
 * @Description: 订单数据访问层
 * @since: 2025-07-08
 */
@Mapper
public interface OrderMapper extends BaseMapper<Order> {

    /**
     * 根据订单id查询
     *
     * @param id 订单id
     * @return 订单详情
     */
    @Select("SELECT * FROM orders WHERE id = #{id}")
    Order selectById(@Param("id") Long id);

    /**
     * 插入订单
     *
     * @param order 订单详情
     * @return
     */
    @Insert("INSERT INTO orders (user_id, product_id, count, money, status) VALUES (#{userId}, #{productId}, #{count}, #{money}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Order order);

    /**
     * 更新订单状态
     *
     * @param id     订单id
     * @param status 订单状态
     * @return
     */
    @Update("UPDATE orders SET status = #{status} WHERE id = #{id}")
    int updateStatus(@Param("id") Long id, @Param("status") Integer status);

    /**
     * 根据用户id查询
     *
     * @param userId 用户id
     * @return
     */
    List<Order> selectByUserId(String userId);

    /**
     * 更新订单
     *
     * @param order 订单详情
     * @return
     */
    int updateOrder(Order order);

}
